package com.csglxt.service.impl;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csglxt.base.DaoSupportImpl;
import com.csglxt.domain.User;
import com.csglxt.service.UserService;

/**
 * 
 * @ClassName: UserServiceImpl
 * @Description:用户业务实现类
 * @author Delver_Si
 * @date 2015-5-28 下午11:52:00
 * 
 */
@Service
@Transactional
public class UserServiceImpl extends DaoSupportImpl<User> implements
        UserService {
    /**
     * 根据用户名和密码查询用户
     */
    public User findByUsernameAndPassword(User user) {
        return (User) getSession().createQuery(//
                "FROM User u WHERE u.username=? AND u.password=?")//
                .setParameter(0, user.getUsername())//
                .setParameter(1, DigestUtils.md5Hex(user.getPassword()))//
                .uniqueResult();
    }

    /**
     * ajax验证查询用户是否已存在
     */
    public User findByUsername(User user) {
        return (User) getSession().createQuery(//
                "FROM User u WHERE u.username=?")//
                .setParameter(0, user.getUsername())//
                .uniqueResult();
    }

}
